<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ page import="com.hzqy.commons.utils.ConstantUtils" %>
<%@ taglib prefix="limits" uri="/WEB-INF/tld/limits.tld"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>客户账号管理列表页</title>
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/defalut.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/public.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/ddspstyle.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"	href="../../static/js/themes/icon.css">
<link href="../../static/css/uploadify.css" rel="stylesheet" type="text/css"/>


<script type="text/javascript" src="../../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../../static/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../../static/js/index.js"></script>
<script src="../../static/js/jquery.uploadify.js" type="text/javascript"></script>

<%
String []nonceObj=ConstantUtils.getNonceObject();
%>
<script type="text/javascript">
		var queryParams;
		function EasyuiDatagrid() {
			$("#easyui-datagrid").datagrid({
				url: '../../content/content_list.do',
				nowrap: true,
				striped: true,
				border: false,
				fit: true,
				rownumbers:true,
				queryParams: getGueryParams(),
				columns: [[
					{field:'id',checkbox:true},
					{field:'f_cc_id',title:'账号ID',align:'center',width:50},
					{field:'f_cc_companyname',title:'所属行业客户',align:'center',width:150},
					{field:'f_cc_searchname',title:'客户名称',align:'center',width:150,
						formatter:function(value,row,index) {
							return encryption(value);
						}
					},
					{field:'f_cc_obligate1',title:'客户地址',align:'center',width:150,
						formatter:function(value,row,index) {
							return encryption(value);
						}
					},
					{field:'f_cc_name',title:'业务账号',align:'center',width:150,
						formatter:function(value,row,index) {
							return encryption(value);
						}
					},
					{field:'f_cc_cdate',title:'添加时间',align:'center',width:150,
						formatter:function(value,row,index) {
							var str = "";
							if(value!=null)
								str = value.substring(0,19);
							return str;
						}	
					},
					{field:'f_cc_udate',title:'最近修改时间',align:'center',width:150}
				]],
				singleSelect:false,
				pagination:true,
				pageList:[10,20,30,40,50],
				pageSize:10,
				toolbar: '#toolbar',
				
				onExpandRow: function(index,row){
				
				},
				onSelect: function(rowIndex,rowData) {
					
				},
				onUnselect: function(rowIndex,rowData) {
					
				},
				onCheckAll: function(rowIndex,rowData) {
					
				},
				onUncheckAll: function(rowIndex,rowData) {
				
				},
				onLoadSuccess: function(data) {
					if(data.total==-1) {
						$.messager.defaults={ok:"确定",cancel:"取消"};
						$.messager.confirm('提示', '用户尚未登录,请登录', function(r){
						if (r){
						    window.parent.location.href='/login.do';
						    return false;
						}});
					}
				}
			});
		}
		
		function getGueryParams(){
			return {
				f_cc_name:$("#f_cc_name").val(),
				f_cc_searchname:$("#f_cc_searchname").val(),
				f_cc_status:$("#f_cc_status").val(),
				f_cc_type:$("#f_cc_type").val(),
				f_cc_companyid:$("#f_cc_companyid").val()
			};
		}
		
		$(function(){
			new EasyuiDatagrid();
			gotoSearch = function(){
				$("#easyui-datagrid").datagrid('reload',getGueryParams());
			};
		});
		
		function SubgridTabOnSelect(title,index){
			setTimeout(function(){
				$("#easyui-datagrid").datagrid('fixDetailRowHeight',index);
			},300);
			setTimeout(function(){
				$("#easyui-datagrid").datagrid('fixDetailRowHeight',index);
			},3000);
	    }
		
		function load(){
			$(".datagrid-row-expander datagrid-row-expand").attr("display","none"); 
		}
		
		function onpress(){
			var event=arguments.callee.caller.arguments[0]||window.event;//消除浏览器差异
	   		  	if (event.keyCode == 13){  
	      			gotoSearch($('#easyui-treegrid'));
	    		}
		}
		
		function add() {
			openDialog($('#dlg'),'customer_account_add.jsp');
		}
		
		function edit() {
			var rows = $("#easyui-datagrid").datagrid('getSelections');
			var ids = '';
			if(rows.length != 1) {
				alert("请选择一条记录!");
			} else {
				openDialog($('#dlg'),'customer_account_update.jsp?f_cc_id='+rows[0].f_cc_id);
			}	
		}
		
		function batchDelete() {
			var rows = $("#easyui-datagrid").datagrid('getSelections');
			var ids = '';
			if(rows.length <= 0) {
				alert("请至少选择一条记录!");
			} else {
				if(confirm("确认是否删除这些账号？")){
					for(var i=0;i<rows.length;i++) {
						ids += rows[i].f_cc_id + ',';
					}
					ids = ids.substring(0, ids.length - 1);
					$.ajax({
						url:"../../content/batch_delete_content.do?stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>",
						dataType : 'json',
						data : {ids : ids},
						type : 'get',
						success:function(data) {
							alert(data.result);
							gotoSearch($('#easyui-treegrid'));
							window.location.reload();
						}
					});
				}
			}
		}
		
		function orgSelect(){
			openDialog($('#org_list'),'../behavior_control/org_update.jsp?idField=f_cc_companyid&nameField=f_cc_companyname');
		}
		function reSet(){
			$("#f_cc_companyname").val("");
			$("#f_cc_companyid").val("");
		}
		function exportExcel(){
			var pager = $("#easyui-datagrid").datagrid("getPager").data("pagination").options;;
			var page=pager.pageNumber;
			var rows=pager.pageSize;
			var f_cc_name=$("#f_cc_name").val();
			var f_cc_status=0;
			var f_cc_type=100;
			var sourceFlag=1;
			var f_cc_companyid=$("#f_cc_companyid").val();
			if(!f_cc_companyid||f_cc_companyid==0||f_cc_companyid==''){
				alert("请选择客户");
				return;
			}
			var url="../../content/content_excel_list.do?f_cc_name="+f_cc_name+"&sourceFlag="+sourceFlag+"&f_cc_status="+f_cc_status+"&f_cc_type="+f_cc_type+"&f_cc_companyid="+f_cc_companyid+"&page="+page+"&rows="+rows;
			window.open(url);
		}
	</script>
</head>
<body onload="load();" style="width: 100%;">
	<input type="hidden" id="sessionId" value="${pageContext.session.id}" />
	<input type="hidden" id="f_cc_status" name="f_cc_status" value="1" />
	<input type="hidden" id="f_cc_type" name="f_cc_type" value="100" />
	<table id="easyui-datagrid" title="账号列表"></table>
	<div id="toolbar" class="easyui_datagrid_toolbar" style="">
		<div class="easyuiSearch">
			<form onsubmit="return false;" method="post">
				<table cellspacing="0" cellpadding="0" width="100%">
					<tr>
						<td align="left" width="20%">
						<limits:uiAuth url="insert_content.do">
							<a href="javascript:void(0);" class="easyui-linkbutton"
								data-options="iconCls:'icon-add', plain:true" onclick="add()">添加</a>
						</limits:uiAuth>
						<limits:uiAuth url="update_content.do">
							<a href="javascript:void(0);" class="easyui-linkbutton"
								data-options="iconCls:'icon-edit', plain:true" onclick="edit()">修改</a>
						</limits:uiAuth>
						<limits:uiAuth url="batch_delete_content.do">
							<a href="javascript:void(0);" class="easyui-linkbutton"
								data-options="iconCls:'icon-remove', plain:true" onclick="batchDelete()">删除</a>
						</limits:uiAuth>
						</td>
						<td align="left" width="7%">客户姓名：</td>
						<td align="left" width="14%"><input name="f_cc_searchname" id="f_cc_searchname" style="width: 120px;" onkeydown="onpress();" /></td>
						<td align="left" width="7%">客户账号：</td>
						<td align="left" width="14%"><input name="f_cc_name" id="f_cc_name" style="width: 120px;" onkeydown="onpress();" /></td>
						<td align="left" width="7%">行业客户：</td>
						<td align="left" width="24%">
							<input name="f_cc_companyname" id="f_cc_companyname" readonly="readonly"	style="width: 120px;" value="" class="yl_inp yw_name" /> 
							<input type="hidden" id="f_cc_companyid" name="f_cc_companyid"  value=""/>
							<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0);"
							onclick="orgSelect()">选择</a>
							<limits:uiAuth url="content_list.do">
								<a href="javascript:void(0);" class="easyui-linkbutton"
									data-options="iconCls:'icon-cancel', plain:true"
									onclick="reSet()">重置</a>
							</limits:uiAuth>
						</td>
						
						<td align="left" width="10%">
							<limits:uiAuth url="content_list.do">
								<a href="javascript:void(0);" class="easyui-linkbutton"
									data-options="iconCls:'icon-search', plain:true"
									onclick="gotoSearch($('#easyui-datagrid'))">查询</a>
							</limits:uiAuth>
							<limits:uiAuth url="content_excel_list.do">
								<a href="javascript:void(0);" class="easyui-linkbutton"
									data-options="iconCls:'icon-save', plain:true"
									onclick="javascript:exportExcel()">导出Excle</a>
							</limits:uiAuth>
						</td>
					</tr>
				</table>
			</form>
		</div>
	</div>
	<div id="dlg" class="easyui-dialog"
		style="width: 950px; height: 600px; padding-top: 0px;"
		data-options="title:'账号管理', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
		<iframe scrolling="auto" frameborder="0"
			style="width: 100%; height: 99%;"></iframe>
	</div>
	<div id="org_list" class="easyui-dialog"
		style="width: 800px; height: 500px; padding-top: 0px;"
		data-options="title:'客户选择', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
		<iframe scrolling="auto" frameborder="0"
			style="width: 100%; height: 99%;"></iframe>
	</div>
</body>
</html>